﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Text;
using Liger.Web.Common;

namespace Liger.Web.UI
{
   

    public class UIComponentBuilderBase  : IHideObjectMembers
    {
        protected UIComponentBase Component;

        public UIComponentBuilderBase(UIComponentBase component)
        {
            this.Component = component;
        }


        public override string ToString()
        {
            this.Component.Render(); 

            return this.Component.ToString();
        }

        public virtual UIComponentBuilderBase LoadInDocumentReady(bool b)
        {
            this.Component.LoadInDocumentReady = b;

            return this;
        }

        /// <summary>
        /// 绑定事件
        /// </summary>
        /// <param name="evenName"></param>
        /// <param name="evenFn"></param>
        /// <returns></returns>
        public virtual UIComponentBuilderBase Bind(string evenName, string evenFn)
        {
            if (!evenName.StartsWith("on"))
            {
                evenName = "on" + evenName;
            }
            if (this.Component.Events.ContainsKey(evenName))
            {
                this.Component.Events[evenName] = () => evenFn;
            }
            else
            {
                this.Component.Events.Add(evenName, () => evenFn);
            }
            return this;
        }
        /// <summary>
        /// 解除事件
        /// </summary>
        /// <param name="evenName"></param>
        /// <returns></returns>
        public virtual UIComponentBuilderBase UnBind(string evenName)
        {
            if (!evenName.StartsWith("on"))
            {
                evenName = "on" + evenName;
            }
            if (this.Component.Events.ContainsKey(evenName))
            {
                this.Component.Events.Remove(evenName);
            }
            return this;
        }
    }
}
